# 方法一 n^2, n 
class Solution:
    def numOfUnplacedFruits(self, fruits: List[int], baskets: List[int]) -> int:
        n = len(baskets)
        flag = [False] * n # 标记篮子里是否有水果
        temp = 0 # 记录放了几个水果
        for x in fruits:
            for i in range(n):
                if flag[i]: # 有水果直接跳过
                    continue
                if x <= baskets[i]:
                    flag[i] = True
                    temp += 1
                    break
                else:
                    continue
        return (n - temp)# 返回未放入的数量
# 方法二， 方法一改进，空间为O（1）
class Solution:
    def numOfUnplacedFruits(self, fruits: List[int], baskets: List[int]) -> int:
        n = len(baskets)
        count = 0 # 统计未放入水果数量
        for x in fruits:
            unset = 1
            for i in range(n):
                if x <= baskets[i]:
                    baskets[i] = 0
                    unset = 0
                    break
            count += unset
        return count